package com.ling.core.view.builder;

import com.bstek.dorado.view.widget.form.Label;
import com.ling.core.view.ViewComponent;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class LabelBuilder extends AbstractControlBuilder {

    public void build(Object control, ViewComponent parentViewComponent) {
        Label label = (Label) control;
        String id = label.getId();
        ViewComponent component = null;
        if (StringUtils.isNotEmpty(id)) {
            component = this.generateViewComponent(id, Label.class);
            if (StringUtils.isEmpty(label.getText())) {
                component.setDesc(label.getText());
            }
        } else if (StringUtils.isEmpty(label.getText())) {
            component = this.generateViewComponent(label.getText(), Label.class);
        }
        if (component != null) {
            if (StringUtils.isEmpty(component.getId())) {
                component.setEnabled(false);
            }
            parentViewComponent.addChildren(component);
        }
    }

    public boolean support(Object control) {
        return control instanceof Label;
    }

}
